package org.candan.spider.task.xml;

import org.candan.spider.bean.Result;
import org.dom4j.Element;
import org.dom4j.tree.DefaultElement;

public class ResultXMLParse {

	/**
	 * @category result转换成XML
	 * @param result
	 * @return
	 */
	public Element resultToXML(Result result){
		Element el = new DefaultElement(XMLProperty.result);
		el.addAttribute(XMLProperty.name, result.getName());
		el.addAttribute(XMLProperty.size, result.getSize());
		el.addAttribute(XMLProperty.path, result.getPath());
		return el;
	}
	
	/**
	 * @category xml转换成result实体类
	 * @param el
	 * @return
	 */
	public Result  xmlToResult(Element el){
		Result result = new Result();
		result.setName(el.attributeValue(XMLProperty.name));
		result.setSize(el.attributeValue(XMLProperty.size));
		result.setPath(el.attributeValue(XMLProperty.path));
		return result;
	}
}
